//
//  ZZCEmoticonButton.swift
//  weibo
//
//  Created by zhangzuchao on 2017/4/8.
//  Copyright © 2017年 zhangZuChao. All rights reserved.
//

import UIKit

class ZZCEmoticonButton: UIButton {
    
    //  关联的表情模型
    var emoticon: ZZCEmoticon? {
        didSet {
            //保证不为空
            guard let currentEmoticon = emoticon else {
                return
            }
            self.isHidden = false
            if currentEmoticon.type == "0" {
                
                //  图片表情
                self.setImage(UIImage(named: currentEmoticon.path!), for: .normal)
                self.setTitle(nil, for: .normal)
            } else {
                
                //  emoji表情
                let emoji = (currentEmoticon.code! as NSString).emoji()
                self.setTitle(emoji, for: .normal)
                self.setImage(nil, for: .normal)
            }
        }
    }
}
